﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.InteropServices;

namespace JsonRpc
{ /// <summary>
    /// 插件启动策略
    /// </summary>
    public enum InitPolicy
    {
        /// <summary>
        /// 延迟加载 
        /// 需要的时候再反射加载
        /// </summary>
        Lazy = 0,
        /// <summary>
        /// 在导入插件的时候就直接反射加载
        /// </summary>
        Direct = 1
    }
    /// <summary>
    /// 插件属性
    /// </summary>
    [AttributeUsage(AttributeTargets.Class)]
    public class PluginAttribute : Attribute
    {

        #region 插件信息
        /// <summary>
        /// 插件版本信息
        /// </summary>
        public Version PluginVersion { set; get; }

        /// <summary>
        /// 插件展示名
        /// </summary>
        public string DisplayName { set; get; }

        /// <summary>
        /// 插件识别符
        /// </summary>
        public string Identify { set; get; }

        /// <summary>
        /// 插件的Guid
        /// </summary>
        public int Id { set; get; }

        /// <summary>
        /// 插件接口的名字
        /// </summary>
        public string PluginInterfaceName { set; get; }

        /// <summary>
        /// 类路径
        /// </summary>
        public string PluginDllPath { set; get; }

        /// <summary>
        /// 启动策略
        /// </summary>
        public InitPolicy StartPolicy { set; get; }

        /// <summary>
        /// 加载的时候对dll进行初始化操作的类
        /// </summary>
        public string Activator { set; get; }
        #endregion
    }
    //<PluginVersion>1.0.0.0</PluginVersion>
    //<DisplayName>提供给插件容器使用的插件名字</DisplayName>
    //<Identify>插件实现类的完整类名(包含名字空间)</Identify>
    //<Id>插件唯一标识符GUID如果有按照该ID来加载插件的必须提供</Id>
    //<PluginInterfaceName>协议接口信息</PluginInterfaceName>
    //<PluginDllPath>插件的物理名称(如果插件物理路径和插件描述文件不再同一目录下面则要加上相应的路径地址)</PluginDllPath>
    //<StartPolicy>加载模式-直接加载在扫描插件目录的时候就会直接进行一次加载--延迟加载则是再调用的时候才会加载如果不用就不会加载到内存中</StartPolicy>
    //<Activator>插件初始化类--必须继承与插件核心组件提供的初始化接口</Activator>

    class TT
    {
        public Int32 a { set; get; }
        public Int32 b { set; get; }
    }




    public class Quotient
    {
        public int Quo { set; get; }
        public int Rem { set; get; }
    }


    class Program
    {

        public static Dictionary<string, long> RpcMap = new Dictionary<string, long>();


        class UpdateVersion
        {
            public int Soft { set; get; }
            public int Data { set; get; }

            public string Tips { set; get; }
        }


        [DllImport("test.dll")]
      private static  extern void test();


        static void Main(string[] args) {

            Console.WriteLine(UInt64.MaxValue);
           
            //var module = new Justin.OSGI.Module(version: new Version(1, 0, 1));
            //module.SetModuleState(Justin.OSGI.ModuleState.Installing);
            //Console.WriteLine("{0}:{1}->{2}", module.ModuleName, module.ModuleDescription, module.ModuleVersion);

            //try {
            //    var s0 = Justin.Service.ServieSingleton.GetService<IMrsoft>();
            //    s0.Show("hello");

            //    var s1 = Justin.Service.ServieSingleton.GetService<IMrsoft>();
            //    s1.Show("hello");

            //    var s2 = Justin.Service.ServieSingleton.GetService<IMrsoft>();
            //    s2.Show("hello");

            //}
            //catch (Exception ex) {
            //    Console.WriteLine(ex.Message);
            //}


           //var ii = new Justin.OSGI.Addin();
            //ii.SetMeta("name", "test");
            //ii.SetMeta("author", "漠然");
            //ii.SetMeta("version", "15.1.1.0");

            //Console.WriteLine("{0}{1}{2}", ii.Name, ii.Author, ii.Ver);

            //test();
            //var v = new UpdateVersion() {
            //    Soft = 21,
            //    Data = 22,
            //    Tips = "修改启动入口,更新到40之后使用launch.exe进行启动！"
            //};

            //System.IO.File.WriteAllText("c:\\a.txt", Newtonsoft.Json.JsonConvert.SerializeObject(v));

            //Console.WriteLine(Newtonsoft.Json.JsonConvert.SerializeObject(v));

            //test();
            Console.ReadKey();

            //创建一个代理对象:这样就会自动创建一个代理方法 sayHi();
        }

        //private static void test() {
        //    var t1 = new JsonRpc.JsonRequest("Arith.Multiply", 1, new TT() { a = 1, b = 2 });
        //    var t2 = new JsonRpc.JsonRequest("Arith.Divide", 2, new TT() { a = 1, b = 2 });

        //    var call = new JsonRpc.JsonRpcClient("192.168.0.5", 12981);
        //    var i = call.Call<int>(t1);

        //    var r = call.Call<Quotient>(t2);
        //    Console.WriteLine("结果如下：{0}", i);
        //    Console.WriteLine("结果如下：{0}：{1}", r.Quo, r.Rem);
        //}
    }

}
